package com.block.product.factory;

import com.block.common.util.ApplicationContextUtil;
import com.block.product.enums.UnionTypeEnum;
import com.block.product.service.IUnionLoginService;
import com.block.product.service.union.DefaultUnionLoginService;
import com.block.product.service.union.MengXinHuaUnionLoginService;
import com.block.product.service.union.QianXiaoHuaUnionLoginService;
import com.block.product.service.union.YongQianFenqiUnionLoginService;

import java.util.HashMap;
import java.util.Map;

public class UnionLoginFactory {

    private static final Map<String, Class<? extends IUnionLoginService>> serviceMap = new HashMap<>();
    static {
        serviceMap.put(UnionTypeEnum.DEFAULT.getValue(), DefaultUnionLoginService.class);
        serviceMap.put(UnionTypeEnum.YONGQIANFENQI.getValue(), YongQianFenqiUnionLoginService.class);
        serviceMap.put(UnionTypeEnum.QIANXIAOHUA.getValue(), QianXiaoHuaUnionLoginService.class);
        serviceMap.put(UnionTypeEnum.MENGXINHUA.getValue(), MengXinHuaUnionLoginService.class);
    }

    public static IUnionLoginService getService(String accountType){
        if (serviceMap.containsKey(accountType)){
            Class<? extends IUnionLoginService> aClass = serviceMap.get(accountType);
            return ApplicationContextUtil.getBean(aClass);
        }
        return null;
    }

}
